package com.neusoft.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Food;
import com.neusoft.service.FoodService;

@RestController
@RequestMapping("/FoodController")
@RefreshScope //开启动态刷新
public class FoodController {
	
	@Autowired
	private FoodService foodService;

	@GetMapping("/listFoodByBusinessId/{businessId}")
	public CommonResult<List> listFoodByBusinessId(Food food) throws Exception{
		return new CommonResult(200, "success", foodService.listFoodByBusinessId(food.getBusinessId()));
	}
	
	@PutMapping("/setFoodPriceByFoodId/{foodId}/{foodPrice}")
	public CommonResult<Integer> setFoodPriceByFoodId(@PathVariable Integer foodId, @PathVariable Double foodPrice) throws Exception {
		return new CommonResult(200, "success", foodService.setFoodPriceByFoodId(foodId, foodPrice));
	}

	@PutMapping("/setFoodQuantityByFoodId/{foodId}/{quantity}")
	public CommonResult<Integer> setFoodQuantityByFoodId(@PathVariable Integer foodId, @PathVariable Integer quantity) throws Exception {
		return new CommonResult(200, "success", foodService.setFoodQuantityByFoodId(foodId, quantity));
	}
}
